<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- <link rel="stylesheet" href=""> -->
    <style>
        .wrap {
            margin-top: 10px;
        }
    </style>
</head>

<body>
    <button class="switch">switch</button>
    <div class="wrap">
        <a href="https://www.baidu.com" target="_self">
            <img src="../images/bg.jpg" width="400" alt="">
        </a>
    </div>
</body>
<script>

    // href   获取和设置元素的href属性  (a link)
    // target 获取和设置元素的target属性
    // src    获取和设置元素的src属性   (img script video audio)

    // width  获取和设置图片的width属性
    // height  获取和设置图片的height属性

    var switchBtn = document.getElementsByClassName("switch")[0];
    var a = document.querySelector("a");
    var img = document.querySelector("img");

    switchBtn.onclick = function () {
        // 取值
        // console.log(a.href);
        // console.log(a.target);
        // console.log(img.src);
        // console.log(img.width);
        // console.log(img.height);

        // 赋值

        a.href = "https://www.jd.com";
        a.target = "_blank";
        img.src = "../images/bg_5.jpeg";
        img.width = "200";

    }



</script>

</html>